#pragma once

#include <QObject>

#include "tccore_global.h"

#include "Request\PersonalInfo.h"

namespace TC
{
    namespace Request
    {
        class Login;
        class UserInfo;
        class PersonalInfo;
    }
    namespace Data
    {
        class TCCORE_EXPORT User : public QObject
        {
            Q_OBJECT;
//             Q_PROPERTY(QByteArray signature READ signature NOTIFY signatureChanged);
			Q_PROPERTY(bool isLogged READ isLogged NOTIFY isLoggedChanged);
			Q_PROPERTY(bool isTourist READ isTourist NOTIFY isTouristChanged);
			Q_PROPERTY(bool isUser READ isUser NOTIFY isUserChanged);
			Q_PROPERTY(bool isAdmin READ isAdmin NOTIFY isAdminChanged);

            Q_PROPERTY(QString name READ name NOTIFY nameChanged)
            Q_PROPERTY(QString head READ head NOTIFY headChanged)
            Q_PROPERTY(uint level READ level NOTIFY levelChanged)
            Q_PROPERTY(bool sex READ sex NOTIFY sexChanged)
            Q_PROPERTY(QString email READ email NOTIFY emailChanged)
            Q_PROPERTY(QString phone READ phone NOTIFY phoneChanged)
            Q_PROPERTY(QString province READ province NOTIFY provinceChanged)
            Q_PROPERTY(QString city READ city NOTIFY cityChanged)


        private:
            User();
            ~User();
        public:
            QByteArray signature() { return _signature; };
			bool isLogged() { return !_signature.isEmpty(); };
			bool isUser() { return _isUser; };
			bool isTourist() { return _isTourist; };
			bool isAdmin() { return _isAdmin; };
            QString name() { return _name; }
            QString head() { return _head; }
            uint level() { return _level; }
            bool sex() { return _sex; }
            QString email() { return _email; }
            QString phone() { return _phone; }
            QString province() { return _province; }
            QString city() { return _city; }

        private:
			void setSignature(const QByteArray &data);
			void setIsUser(bool newVal) { if (newVal != _isUser) { _isUser = newVal; isUserChanged(); } }
			void setIsTourist(bool newVal) { if (newVal != _isTourist) { _isTourist = newVal; isTouristChanged(); } }
			void setIsAdmin(bool newVal) { if (newVal != _isAdmin) { _isAdmin = newVal; isAdminChanged(); } }
            void setName(QString newVal) { if (_name != newVal) { _name = newVal; nameChanged(); } }
            void setHead(QString newVal) { if (_head != newVal) { _head = newVal; headChanged(); } }
            void setLevel(uint newVal) { if (_level != newVal) { _level = newVal; levelChanged(); } }
            void setSex(bool newVal) { if (_sex != newVal) { _sex = newVal; sexChanged(); } }
            void setEmail(QString newVal) { if (_email != newVal) { _email = newVal; emailChanged(); } }
            void setPhone(QString newVal) { if (_phone != newVal) { _phone = newVal; phoneChanged(); } }
            void setProvince(QString newVal) { if (_province != newVal) { _province = newVal; provinceChanged(); } }
            void setCity(QString newVal) { if (_city != newVal) { _city = newVal; cityChanged(); } }

        public:
			Q_SIGNAL void signatureChanged();
			Q_SIGNAL void isUserChanged();
			Q_SIGNAL void isTouristChanged();
			Q_SIGNAL void isAdminChanged();
            Q_SIGNAL void isLoggedChanged();
            Q_SIGNAL void nameChanged();
            Q_SIGNAL void headChanged();
            Q_SIGNAL void levelChanged();
            Q_SIGNAL void sexChanged();
            Q_SIGNAL void subjectChanged();
            Q_SIGNAL void emailChanged();
            Q_SIGNAL void phoneChanged();
            Q_SIGNAL void provinceChanged();
            Q_SIGNAL void cityChanged();

        private:
			QByteArray _signature;
			bool _isUser = false;
			bool _isTourist = false;
			bool _isAdmin = false;
            bool _isBasicInfoSet = false;
            QString _name = "";
            QString _head = "";
            uint _level = 11;
            bool _sex = false;
            QString _email = "";
            QString _phone = "";
            QString _province = "";
            QString _city = "";


        private:
            Request::PersonalInfo personalInfoRequest;

        public:
            static User* instance();
        private:
            static User* _instance;

            friend class Request::Login;
            friend class Request::UserInfo;
            friend class Request::PersonalInfo;
        };
    }
}